// Y in XYZ color-space
const float3 lumVec = float3(0.2126, 0.7152, 0.0722);

/// Tonemap and gamma-correct
float3 SimpleTMandGamma(float3 c, float fExpo, float fGamma) {
	/// TONE MAPPING
	// compress the luminance domain
	float3 L_r;
	L_r[0] = dot(lumVec,c);//compute luminance
	L_r[1] = L_r[0]*fExpo;
	L_r[2] = L_r[1] / (1 + L_r[1]);
	c *= L_r[2]/L_r[0];
	
	// correct for the gamma
	c = pow(c,fGamma);	
	return c;
}

/// construct an under-constrained coordinate from based upon a direction
float3x3 constructCoordFrame(float4 lobe, float3 u) {
	float3x3 smpl2Local;
	
	u = normalize(u);
	smpl2Local._m20_m21_m22 = u;

	// generate under-constrained orthogonal direction using
	// the assumption the reflection direction is axis aligned
	smpl2Local._m00_m01_m02 = normalize(float3(0,u.z,-u.y));
	
	// Find the remaining component in the orthogonal coordinate frame
	smpl2Local._m10_m11_m12 = cross(smpl2Local._m20_m21_m22, smpl2Local._m00_m01_m02);
	
	return smpl2Local;
	
}
